package com.kstech.mp3604.fragments

import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.SPUtils
import com.kstech.mp3604.base.BaseDialogFragment
import com.kstech.mp3604.base.Global
import com.kstech.mp3604.base.HomeViewModel
import com.kstech.mp3604.databinding.FragmentDialogAutoHYBinding

class DialogAutoHYFragment :
    BaseDialogFragment<FragmentDialogAutoHYBinding>(FragmentDialogAutoHYBinding::inflate) {
    private lateinit var mViewModel: HomeViewModel
    override fun onInitView() {
        mViewModel = ViewModelProvider(requireActivity())[HomeViewModel::class.java]
        binding.apply {
            val value = SPUtils.getInstance().getInt(Global.APP_AUTOHY_VALUE)
            if (value != -1) {
                hyWidth.setText(value.toString())
            }
            closeDialog.setOnClickListener {
                dialog!!.cancel()
            }
            submit.setOnClickListener {
                val hyWidth = hyWidth.text.toString().trim()
                if (!hyWidth.isEmpty()) {
                    val hyWidth = hyWidth.toInt()
                    SPUtils.getInstance().put(Global.APP_AUTOHY_VALUE, hyWidth)
                    Global.app_autoHY_value = hyWidth
                    mViewModel.autoHYListener.saveAutoHYSuccess()
                    dialog!!.cancel()
                }
            }
        }
    }
}